/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.diplomka.webapp.building;

import cz.fi.muni.diplomka.common.Coordinates;
import cz.muni.fi.diplomka.servicelayer.gamelogic.manager.CityBuildingManager;
import cz.muni.fi.diplomka.servicelayer.gamelogic.managerimpl.CityBuildingManagerImpl;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;

/**
 *
 * @author Jakub Kutil
 */
public class RazePanel extends Panel {

    private CityBuildingManager cityBuildingManager = new CityBuildingManagerImpl();
    private Long cityId = new Long(0);
    private int x = 0;
    private int y = 0;

    public RazePanel(String id, final PageParameters parameters) {
        super(id);

        if (parameters.containsKey("cityId")) {
            cityId = Long.parseLong(parameters.getString("cityId"));
        }

        if (parameters.containsKey("x")) {
            x = Integer.parseInt(parameters.getString("x"));
        }

        if (parameters.containsKey("y")) {
            y = Integer.parseInt(parameters.getString("y"));
        }

        Form<?> form = new Form<Void>("form") {
            @Override
            protected void onSubmit() {

                Coordinates c = new Coordinates();
                c.setX_coordinate(x);
                c.setY_coordinate(y);

                cityBuildingManager.razeBuilding(cityId, c);

                info("Building has been razed.");
                setResponsePage(BuildingPage.class, parameters);
            }
        };

        add(form);
    }
}
